package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.model.main.CommInfo;

/**
 * 
 * @author wzk
 *
 */
@Repository
public class CommInfoDAOImpl  {/*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public CommInfo queryCommInfoByUserid(int userid, int cardid,int type)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "SELECT * FROM comminfo WHERE user_id = ? and card_id=? and type=?";
		CommInfo commInfo = jdbcTemplate.queryForObject(sql, new Object[] { userid,cardid,type}, new CommInfoMapper());
		CustomerContextHolder.clearCustomerType();
		return commInfo;
	}

	@Override
	public int saveCommInfo(CommInfo commInfo) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("INSERT INTO comminfo (user_id,card_id,type) VALUES (?,?,?)");		
		Object[] params = {commInfo.getUserid(),commInfo.getCardid(),commInfo.getType()};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	private static final class CommInfoMapper implements RowMapper<CommInfo> {
		public CommInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
			CommInfo commInfo = new CommInfo();
			commInfo.setCommid(rs.getInt("id"));
			commInfo.setUserid(rs.getInt("user_id"));
			commInfo.setCardid(rs.getInt("card_id"));
			commInfo.setStatus(rs.getInt("status"));
			return commInfo;
		}
	}*/
}
